package com.eimf.saf.security.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.eimf.saf.base.action.BaseAction;
import com.eimf.saf.security.util.ImageCodeUtil;

/**
 * 验证码
 * 
 * @author eden
 * 
 */
@Controller
@Scope("prototype")
public class ImageCodeAction extends BaseAction
{
    private static final long serialVersionUID = 1l;

    public void getCode() throws Exception
    {
        final HttpServletRequest request = ServletActionContext.getRequest();
        final HttpServletResponse response = ServletActionContext.getResponse();
        response.setContentType("image/jpeg");
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0L);
        ImageCodeUtil.generateAddCode(request, response);
    }

    public String checkCode()
    {
        return BaseAction.JSON;
    }

}
